/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author danilo
 */
public class Filtro implements Filter{

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
       // throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        
        boolean logado = false;
        HttpServletResponse resp =(HttpServletResponse) response;
        
        if(request.getParameter("logado")!=null){
            logado=Boolean.parseBoolean(request.getParameter("logado"));
        }
        
        if(!logado){
            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
       
     
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
       // throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
